#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
int main(){
  freopen("tree.in","r",stdin);
  freopen("tree.out","w",stdout);
  ios::sync_with_stdio(false);
  int n; static int p; cin>>n>>p;
  if(n==1)cout<<"1\n";
  else if(n==2)cout<<6%p<<endl;
  else if(n==3)cout<<66%p<<endl;
  return 0;
}